OBJECT Report 93 Create Fiscal Year
{
  OBJECT-PROPERTIES
  {
    Date=12/03/15;
    Time=08:14:57;
    Modified=Yes;
    Version List=NAVW17.10,NAVGB7.10,4-4-5;
  }
  PROPERTIES
  {
    CaptionML=[ENU=Create Fiscal Year;
               ENG=Create Fiscal Year];
    ProcessingOnly=Yes;
    OnPreReport=BEGIN
                  IF FiscalYearStartDate = 0D THEN
                    ERROR(Text1041000);

                  AccountingPeriod.SETRANGE("Period Type",AccountingPeriod."Period Type"::Year);
                  IF AccountingPeriod.FINDFIRST THEN BEGIN
                    FirstPeriodStartDate := AccountingPeriod."Period Start";
                    IF AccountingPeriod.FINDLAST THEN
                      LastPeriodStartDate := AccountingPeriod."Period Start";
                    AccountingPeriod.SETRANGE(Closed,TRUE);
                    IF AccountingPeriod.FINDLAST THEN BEGIN
                      FirstPeriodStartDate := AccountingPeriod."Period Start";
                      FirstPeriodLocked := TRUE;
                      IF FiscalYearStartDate < AccountingPeriod."Period Start" THEN
                        IF NOT
                           CONFIRM(
                             Text000 +
                             Text001)
                        THEN
                          EXIT;
                    END;
                  END ELSE
                    IF NOT
                       CONFIRM(
                         Text002 +
                         Text003)
                    THEN
                      EXIT;

                  //4-4-5 Accounting >>
                  IF FourFourFive THEN BEGIN
                    Calendar.RESET;
                    Calendar.SETRANGE("Period Type",Calendar."Period Type"::Month);
                    Calendar.SETRANGE("Period Start",FiscalYearStartDate, 31129999D);
                    Calendar.FIND('-');
                  END;
                  //4-4-5 Accounting <<

                  MonthStartDate := FiscalYearStartDate;
                  FOR i := 1 TO NoOfMonths DO BEGIN
                    IF MonthStartDate <= FirstPeriodStartDate THEN
                      EXIT;
                    IF FirstPeriodStartDate <> 0D THEN
                      IF (MonthStartDate >= FirstPeriodStartDate) AND (MonthStartDate < LastPeriodStartDate) THEN
                        ERROR(Text004);

                    //4-4-5 Accounting >>
                    IF FourFourFive THEN BEGIN
                      IF i MOD 3 <> 0 THEN
                        MonthEndDate := CALCDATE('<4W>',MonthStartDate) - 1
                      ELSE
                        MonthEndDate := CALCDATE('<5W>',MonthStartDate) - 1;
                    END ELSE
                    //4-4-5 Accounting >>
                      MonthEndDate := CALCDATE(MonthLength,MonthStartDate) - 1;

                    AccountingPeriod.INIT;
                    AccountingPeriod."Period Type" := AccountingPeriod."Period Type"::Month;
                    AccountingPeriod."Period Start" := MonthStartDate;
                    AccountingPeriod."Period End" := CLOSINGDATE(MonthEndDate);
                    AccountingPeriod.UpdateName;

                    //4-4-5 Accounting >>
                    IF FourFourFive THEN BEGIN
                      AccountingPeriod."Period No." := i;
                      AccountingPeriod."Period Name" := Calendar."Period Name";
                      Calendar.NEXT;
                    END;
                    //4-4-5 Accounting >>

                    AccountingPeriod.INSERT(TRUE);
                    MonthStartDate := MonthEndDate + 1;
                  END;
                  AccountingPeriod.INIT;
                  AccountingPeriod."Period Type" := AccountingPeriod."Period Type"::Year;
                  AccountingPeriod."Period Start" := FiscalYearStartDate;
                  AccountingPeriod."Period End" := CLOSINGDATE(MonthEndDate);
                  AccountingPeriod.UpdateName;

                  //4-4-5 Accounting >>
                  IF FourFourFive THEN BEGIN
                    EVALUATE(AccountingPeriod."Period No.",FORMAT(NORMALDATE(AccountingPeriod."Period End"),0,'<Year4>'));
                    AccountingPeriod."Period Name" := FORMAT(NORMALDATE(AccountingPeriod."Period End"),0,'<Year4>');
                  END;
                  //4-4-5 Accounting >>

                  IF (AccountingPeriod."Period Start" < FirstPeriodStartDate) AND FirstPeriodLocked THEN
                    AccountingPeriod.VALIDATE(Closed,TRUE);
                  AccountingPeriod.INSERT(TRUE);
                END;

  }
  DATASET
  {
  }
  REQUESTPAGE
  {
    PROPERTIES
    {
      SaveValues=Yes;
      OnOpenPage=BEGIN
                   IF NoOfMonths = 0 THEN BEGIN
                     NoOfMonths := 12;
                     EVALUATE(MonthLength,'<1M>');
                   END;
                   AccountingPeriod.SETRANGE("Period Type",AccountingPeriod."Period Type"::Year);
                   IF AccountingPeriod.FINDLAST THEN BEGIN
                     AccountingPeriod.TESTFIELD("Period End");
                     FiscalYearStartDate := NORMALDATE(AccountingPeriod."Period End") + 1;
                   END;
                 END;

    }
    CONTROLS
    {
      { 1900000001;0;Container;
                  ContainerType=ContentArea }

      { 1900000002;1;Group  ;
                  CaptionML=[ENU=Options;
                             ENG=Options] }

      { 1   ;2   ;Field     ;
                  Name=StartingDate;
                  CaptionML=[ENU=Starting Date;
                             ENG=Starting Date];
                  SourceExpr=FiscalYearStartDate }

      { 1040000;2;Field     ;
                  Name=NoOfMonths;
                  CaptionML=[ENU=No. of Months;
                             ENG=No. of Months];
                  SourceExpr=NoOfMonths }

      { 1040001;2;Field     ;
                  Name=MonthLength;
                  CaptionML=[ENU=Month Length;
                             ENG=Month Length];
                  SourceExpr=MonthLength }

      { 1000000000;2;Field  ;
                  Name=fourfourfive;
                  CaptionML=[ENU=Four Four Five;
                             ENG=Four Four Five];
                  SourceExpr=FourFourFive }

    }
  }
  LABELS
  {
  }
  CODE
  {
    VAR
      Text000@1000 : TextConst 'ENU=The new fiscal year begins before an existing fiscal year, so the new year will be closed automatically.\\;ENG=The new fiscal year begins before an existing fiscal year, so the new year will be closed automatically.\\';
      Text001@1001 : TextConst 'ENU=Do you want to create and close the fiscal year?;ENG=Do you want to create and close the fiscal year?';
      Text002@1002 : TextConst 'ENU=Once you create the new fiscal year you cannot change its starting date.\\;ENG=Once you create the new fiscal year you cannot change its starting date.\\';
      Text003@1003 : TextConst 'ENU=Do you want to create the fiscal year?;ENG=Do you want to create the fiscal year?';
      Text004@1004 : TextConst 'ENU=It is only possible to create new fiscal years before or after the existing ones.;ENG=It is only possible to create new fiscal years before or after the existing ones.';
      AccountingPeriod@1005 : Record 10560;
      Calendar@1000000001 : Record 2000000007;
      NoOfMonths@1040000 : Integer;
      MonthLength@1040001 : DateFormula;
      FiscalYearStartDate@1008 : Date;
      MonthStartDate@1040002 : Date;
      MonthEndDate@1040003 : Date;
      FirstPeriodStartDate@1009 : Date;
      LastPeriodStartDate@1010 : Date;
      FourFourFive@1000000000 : Boolean INDATASET;
      FirstPeriodLocked@1011 : Boolean;
      i@1012 : Integer;
      Text1041000@1041000 : TextConst 'ENU=You must specify Starting Date.;ENG=You must specify Starting Date.';

    PROCEDURE InitializeRequest@1(NewNoOfMonths@1000 : Integer;NewPeriodLength@1001 : DateFormula;StartingDate@1002 : Date);
    BEGIN
      NoOfMonths := NewNoOfMonths;
      MonthLength := NewPeriodLength;
      FiscalYearStartDate := StartingDate;
    END;

    BEGIN
    END.
  }
  RDLDATA
  {
  }
}

